import pandas as pd
file_path = "D:\数据仓库挖掘\\4.关联分析\shopping.csv"
def DataPreprocessing(file_path):

    with open(file_path) as temp_f:
        # get No of columns in each line
        col_count = [len(l.split(",")) for l in temp_f.readlines()]

    column_names = [i for i in range(max(col_count))] #获取最大行的长度，如果不使用最大行的长度会报错，skip好多行
    df = pd.read_csv(file_path, skip_blank_lines=True,
                     header=None, names=column_names)
    df = df.values.tolist() #将datafrom转化为list
    length = len(df)
    for i in range(0, length):
        df[i] = [x for x in df[i] if pd.isnull(x) == False and x != 'nan'] #去除列表里的nan值

    return df


df = DataPreprocessing(file_path)
# print(df)
